package Controller.Goods;

import Dao.GoodsCategoryDao;
import Dto.Goods;
import Service.GoodsService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "listGoods", value = "/ListGoods")
public class ListGoods extends HttpServlet {
    private GoodsService goodsService = new GoodsService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNum = request.getParameter("pageNum");
        try{
            GoodsCategoryDao dao = new GoodsCategoryDao();
            List<String> ListGoods = dao.selectCategory();
            Map<String,Object> map = goodsService.selectGoodsByPage(pageNum==null?1:Integer.valueOf(pageNum));
            request.setAttribute("ListGoods",ListGoods);
            request.setAttribute("map",map);
            request.getRequestDispatcher("/ListGoods.jsp").forward(request,response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}